package com.example.blogother.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xpd.blog.bean.Fired;
import com.xpd.blog.bean.Userinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xpd
 * @since 2024-09-22
 */
public interface FiredMapper extends BaseMapper<Fired> {
    @Select("select * from fired where usid=#{usid} and fid=#{fid}")
    Fired selectByUsidByFid(@Param("usid") int usid,@Param("fid") int fid);

 @Insert("insert into fired values(null,#{usid},#{fid})")
    int insertFired(@Param("usid") int usid,@Param("fid") int fid);
 @Delete("delete  from fired where usid=#{usid} and fid=#{fid}")
 int deleteByIdInt(@Param("usid") int usid,@Param("fid") int fid);



@Results(id="rm1",value = {
        @Result(column = "id",property = "id",id = true),
        @Result(column = "usid",property = "usid"),
        @Result(column = "usid",property = "userinfo",one = @One(
                select = "selectByUsid"
        ))
})
@Select("select * from fired where fid=#{usid} limit #{page}, #{size}")
 List<Fired> selectByUsidAndId(@Param("usid") int usid,@Param("page") int page,@Param("size") int size);
@Select("select * from userinfo where usid=#{usid}")
Userinfo selectByUsid(int usid);

@Results(id="rm2",value = {
        @Result(column = "id",property = "id",id = true),
        @Result(column = "fid",property = "fid"),
        @Result(column = "fid",property = "userinfo",one = @One(
                select = "selectByUsid"
            ))
    })
@Select("select * from fired where usid=#{usid} limit #{page}, #{size}")
List<Fired> selectByusidAttention(@Param("usid") int usid,@Param("page") int page,@Param("size") int size);

//查找粉丝数量前六名的博主
    @Results(
            id="rm3",
            value = {
                    @Result(column = "id",property = "id"),
                    @Result(column = "fid",property = "fid"),
                    @Result(column = "fid",property = "userinfo",one = @One(
                            select = "selectByUsid"
                    ))
            }
    )
    @Select("SELECT f.*, COUNT(*) as count FROM fired f where fid!=#{usid} GROUP BY f.fid ORDER BY count DESC LIMIT 0,6")
    List<Fired> selectfired(int usid);

}
